package day09_charset_io.com.itheima.d2_byte_stream;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class Demo2_FileInputStream {
    public static void main(String[] args) throws IOException {
        FileInputStream is = new FileInputStream("io-app/src/main/java/day09_charset_io/a.txt");
        byte[] buffer = new byte[3];
        int len = is.read(buffer);
        String rs = new String(buffer);
        System.out.println("len = " + len);
        System.out.println("rs = " + rs);
        System.out.println("-------------------------");

        int len2 = is.read(buffer);
        String rs2 = new String(buffer, 0, len2);
        System.out.println("len2 = " + len2);
        System.out.println("rs2 = " + rs2);

        int len3 = is.read(buffer);
        System.out.println("len3 = " + len3);

        System.out.println("-------------------------");
        FileInputStream is2 = new FileInputStream("io-app/src/main/java/day09_charset_io/a.txt");
        byte[] buffer1 = new byte[3];
        int len4;
        while ((len4 = is2.read(buffer1)) != -1) {
            String rs4 = new String(buffer1, 0, len4);
            System.out.println("rs4 = " + rs4);
        }
        is2.close();
    }
}
